package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.DepartmentDAO;
import com.zerosky.crm.po.Contacts;
import com.zerosky.crm.po.Department;
import com.zerosky.crm.po.ExportAllChartSales;
import com.zerosky.crm.service.DepartmentService;
import com.zerosky.crm.util.PageInfo;

@Service(value="departmentService")
public class DepartmentServiceImpl implements DepartmentService {
	@Autowired
	private DepartmentDAO departmentDao;

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Department> getDepartmentList(Map map) {
		return departmentDao.getDepartmentList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Department getDepartmentById(String deptId) {
		return departmentDao.getDepartmentById(deptId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void addDepartment(Department dept) {
		departmentDao.addDepartment(dept);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void updateDepartment(Department dept) {
		departmentDao.updateDepartment(dept);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteDepartmentById(String deptId) {
		departmentDao.deleteDepartmentById(deptId);
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Department> getDepartmentPageInfoList(Map map) {
		PageInfo<Department> page = new PageInfo<Department>();
		int begin = (((int) map.get("page") - 1) * (int) map.get("limit"));
		int pageSize = (int) map.get("limit");
		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<Department> list = departmentDao.getDepartmentList(map);
		page.setList(list);

		int count = departmentDao.countDepartment(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Department> getDeptPhoneBookList() {
		return departmentDao.getDeptPhoneBookList();
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Department> getDeptNameList(String remake) {
		return departmentDao.getDeptNameList(remake);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Contacts> getContactsRemake(Map<String, Object> map) {
		return departmentDao.getContactsRemake(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Contacts> getContactsDept(Map<String, Object> map) {
		return departmentDao.getContactsDept(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Contacts> getContactsBranch(Map<String, Object> map) {
		return departmentDao.getContactsBranch(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Contacts> getContactsTeam(Map<String, Object> map) {
		return departmentDao.getContactsTeam(map);

	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<ExportAllChartSales> getDeptBranchTeam(Map<String, Object> map) {
		return departmentDao.getDeptBranchTeam(map);
	}
}
